package com.example.android

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.ui.platform.LocalContext

class MainActivity : ComponentActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val context = LocalContext.current
            Column {
                Button({
                    MyFlutterActivity.open(context, FlutterMgr.ROUTE_PAGE_DEFAULT)
                }){
                    Text("page-default")
                }
                Button({
                    MyFlutterActivity.open(context, FlutterMgr.ROUTE_PAGE_A)
                }){
                    Text("page-a")
                }
                Button({
                    MyFlutterActivity.open(context, FlutterMgr.ROUTE_PAGE_B)
                }){
                    Text("page-b")
                }
                Button({
                    MyFlutterActivity.open(context, FlutterMgr.ROUTE_PAGE_TEST_METHOD_CHANNEL)
                }){
                    Text("page_test_method_channel")
                }
                Button({
                    MyFlutterActivity.open(context, FlutterMgr.ROUTE_PAGE_LIFECYCLEWATCHER)
                }){
                    Text("LifecycleWatcher")
                }
                Button({
                    MethodChannelMgr.testCallFlutter()
                }){
                    Text("testSendToFlutter")
                }
            }
        }

        // 预加载 FlutterEngine
        FlutterMgr.preWarmFlutterEngine(this)
    }

    override fun onDestroy() {
        super.onDestroy()
        // 释放资源
        FlutterMgr.destroyEngine()
    }
}
